//
//  FeedbackViewController.m
//  WisdomZhuHai
//
//  Created by Ryan on 14-12-3.
//  Copyright (c) 2014 wyd. All rights reserved.
//

#import "FeedbackViewController.h"
#import "Common.h"
#import "ProtocolManager.h"
#import "TransforController.h"

@interface FeedbackViewController ()<UITextViewDelegate>
@property (assign, nonatomic) IBOutlet UITextView *feedback;
@property (retain, nonatomic) IBOutlet UILabel *tips;

@end

@implementation FeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    _feedback.delegate = self;
    [self textViewDidChange:self.feedback];
    
    [self.view addSubview: [TransforController shardeInstanceOfNavigationBarAndStatusBarCoverViewWithY:-65]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)dealloc {
    [_feedback release];
    [_tips release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setFeedback:nil];
    [self setTips:nil];
    [super viewDidUnload];
}

//输入框placehold显示与隐藏
-(void)textViewDidChange:(UITextView *)textView
{
    self.feedback.text = textView.text;
    [self textView:textView shouldChangeTextInRange:textView.selectedRange replacementText:textView.text];
    if (self.feedback.text.length == 0) {
        self.tips.hidden = NO;
    }else{
        self.tips.hidden = YES;
    }
}

//return键盘隐藏
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

+(void)feedbackWithTarget:(id)target selector:(SEL)sel msg:(NSString *)msg
{

    [[ProtocolManager shareInstance] feedBack:@"ANONYUSER" msg:msg OSversion:@"IOS" target:target selector:@selector(didFinishSend:)];
}

//提交建议
- (IBAction)send:(id)sender {
    NSString *feedbackText = [self.feedback text];
    if(feedbackText.length < 1 || [feedbackText isEqualToString:@""]){
        [[Common shareInstance] showAlertViewWithTitle:nil text:@"您还未填写反馈建议 =。=" dismissTime:0.8];
    }else{
        [self.feedback resignFirstResponder];
        [[Common shareInstance] showLoadingViewWithMessage:nil];
        [FeedbackViewController feedbackWithTarget:self selector:@selector(didFinishLogin:) msg:feedbackText];
        [[Common shareInstance] showAlertViewWithTitle:nil text:@"您的反馈建议正在提交，十分感谢您的参与！^_^" dismissTime:0.8];
    }
}

- (void)didFinishSend:(NSDictionary *)dic
{
    [[Common shareInstance] stopLoadingView];
    if(dic == nil)
    {
        NSLog(@"FeedbackViewController didFinishLogin dic is nil");
        return;
    }
    [[Common shareInstance] showAlertViewWithTitle:nil text:@"提交成功" dismissTime:0.8];
    [self.navigationController popViewControllerAnimated:YES];
}

@end
